﻿<%@ Page Language="C#" Title="路线管理" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="B_RoadwayPage.aspx.cs" Inherits="STHPMS1.Web.W_View.Basis.B_RoadwayPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <%= UiHelper.RefJsFileHtml("/Scripts/Jquery/ajaxfileupload.js")%>    
    
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Enum.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/JsPage.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Appearance.js")%>

    <script type="text/javascript">      
       
        var _view = new JsPage();
        var _css = new Appearance();

        function onAddClick(){
            _view.AddAction(function () {
                $("#Rdwayid").textbox('readonly',false);
                $('#Beginmp').numberbox('readonly', false);
                $('#Endmp').numberbox('readonly', false);
            });
        }
        function onEditClick() {
            _view.EditAction(function () {
                $("#Rdwayid").textbox('readonly',true);
                $('#Beginmp').numberbox('readonly', true);
                $('#Endmp').numberbox('readonly', true);
            });
        }
        function onRemoveClick () {
            _view.RemoveAction();
        }
        function onSumbitClick(){
            _view.sumbitForm();
        }
        function onCloseClick() {
            _view.closeDialog();
        }

        $(function () {           
            
            $("#btnAdd").on("click", onAddClick);
            $("#btnEdit").on("click", onEditClick);
            $("#btnDel").on("click", onRemoveClick);
            $("#btnSave").on("click",onSumbitClick );
            $("#btnCancel").on("click", onCloseClick);
            $("#btnImpt").on("click", impt);
            $("#btnUpload").on("click", saveFile);
            $("#btnQuit").on("click", closeFile);

            _view.setForm($('#fm'))
                .setDialog($('#dlg'))
                .setDataGrid($('#dg'))
                .loadDataGrid("/api/roadway");
        });

    </script>    

    <script>
        //导入的点击事件
        function impt() {
            $("#linkUpload").text("上传");

            $('#dlgImport').dialog('open');
        }

        function closeFile() {
            $("#linkUpload").text("上传");
            $('#dlgImport').dialog('close');
            $("#fileHid").val('');//清空隐藏域
        }
        //上传
        function ajaxFileUpload() {
            $.ajaxFileUpload
            (
                {
                    url: '/api/roadway/uploadFile', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'file1', //文件上传域的ID
                    dataType: 'string', //返回值类型 一般设置为json
                    success: function (data)  //服务器成功响应处理函数
                    {
                        var file = data.replace('<pre>', '').replace('</pre>', '');
                        //写入隐藏域
                        $("#fileHid").val(file);
                        $("#linkUpload").text("上传成功");
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);

                    }
                }
            )
            return false;
        }
        //上传文件验证
        function upLoad() {
            if ($("#linkUpload").text() == "上传") {
                var file = $("#file1").val();//上传文件
                if (file == "") {
                    alert("请选择上传数据");
                    return;
                }
                else {
                    var extStart = file.lastIndexOf(".");
                    var ext = file.substring(extStart, file.length).toUpperCase();
                    if (ext != ".XLS" && ext != ".XLSX") {
                        alert("请上传有效Excel文件");
                        return;
                    }
                }
                ajaxFileUpload();
            }
        }
        //导入处理
        function saveFile() {
            var file = $("#fileHid").val();//上传后的Excel路径
            if (file == "") {
                alert("请上传数据文件");
                return;
            }
           

            $.ajax({
                url: "/api/roadway/saveFile?file=" + encodeURI(file) ,
                type: "post",
                success: function (msg) {
                    $("#fileHid").val('');//清空隐藏域
                    $('#dlgImport').dialog('close');

                    _view.loadDataGrid();
                },

                error: function (msg) {
                    //错误处理
                    alert(msg.responseText);
                    closeFile();
                }
            });
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table id="dg" class="easyui-datagrid content-place"  data-ajaxcached="false"  data-options='{
                  "title": "路线列表",
                  "toolbar": "#tb",
                  "method": "get",
                  "iconCls": "icon-edit",
                  "width": "auto",
                  "height": "auto",
                  "nowrap": false,
                  "striped": true,
                  "border": true,
                  "collapsible": false,
                  "fit": false,
                  "singleSelect": true,
                  "rownumbers": true,
                  "pagination": true
                }' >
        <thead>
            <tr>
                <th data-options="field:'Rdwayid',editor:'text',width:80,align:'center' ">路线编号</th>
                <th data-options="field:'Name',editor:'text',width:160,align:'center' ">路线名称</th>
                <th data-options="field:'Beginmp',editor:'numberbox',width:120,align:'center',formatter:_css.formatStake">起点桩号</th>
                <th data-options="field:'Endmp',editor:'numberbox',width:120,align:'center',formatter:_css.formatStake">终点桩号</th>
                <th data-options="field:'Admgrd',editor:'text',width:80,align:'center',formatter:formatEnum">行政等级</th>
                <th data-options="field:'Structures',editor:'text',width:200,align:'center' ">构造物</th>
                <th data-options="field:'His_Version',editor:'numberbox',width:20,align:'center',hidden:true ">养护版本</th>
            </tr>
        </thead>
    </table>
   
    <div id="tb">
        <a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" >添加</a>
        <a id="btnEdit"  href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" >编辑</a>
        <a id="btnDel"  href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" >删除</a>
         <a href="/down?type=road" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">模板下载</a>
        <a id="btnImpt" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true" >导入</a> 
     
    </div>

    <div id="dlg" class="easyui-dialog" title="保存数据" style="width:300px;height:300px;padding:10px"  data-options="
                closed:true,
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'">
        <form id="fm" class="easyui-form" method="post" action="/api/roadway" data-options="novalidate:true">
            <table>		
                <tr>
                    <td>路线编号:</td>
                    <td><input id="Rdwayid" name='Rdwayid' class=' easyui-textbox' data-options="required:true,validType:'MaxLength[50]'" /></td>
                </tr>
                <tr>
                    <td>路线名称:</td>
                    <td><input name='Name' class='easyui-textbox'  data-options="required:true,validType:'MaxLength[250]'"/></td>
                </tr>
                <tr>
                    <td>起点桩号:</td>
                    <td><input id="Beginmp" name='Beginmp' class='easyui-numberbox' data-options="required:true,min:0,precision:2,formatter:_css.formatStake,parser:_css.parserStake" /></td>
                </tr>
                <tr>
                    <td>终点桩号:</td>
                    <td><input id="Endmp" name='Endmp' class='easyui-numberbox' data-options="required:true,min:0,precision:2,formatter:_css.formatStake,parser:_css.parserStake" /></td>
                </tr>
                <tr>
                    <td>行政等级:</td>    
                    <td><input name='Admgrd'  class="easyui-combobox"  data-options="prompt:'行政等级',required:true,valueField:'id',textField:'text',url:'/api/data/adminlevel',method:'get' "/></td>
                </tr>
                <tr>
                    <td>构造物:</td>
                    <td><input name='Structures' class='easyui-textbox'    data-options="validType:'MaxLength[250]'"/></td>
                </tr>
                <tr style="display:none">
                    <td>养护版本:</td>
                    <td><input name='His_Version' class='easyui-numberbox' /></td>
                </tr>
		    </table>
        </form>
    </div>

    <div id="dlg-buttons">
		<a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton" >保存</a>
		<a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" >取消</a>
	</div>

     <!--导入数据-->
    <div id="dlgImport" class="easyui-dialog" title="导入数据" style="width: 400px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttonsImport'
			">      
            <table>
                <tr>
                    <td style="width:80px;">导入源:</td>
                    <td>
                        
                        <input id="fileHid" type="hidden" />
                        <input type="file" id="file1" name="file" style="width: 200px"/>
                        <a href="javascript:void(0)" id="linkUpload"  onclick="javascript:upLoad();">上传</a>
                    </td>
                </tr>
               
            </table>
       
    </div>
    <!--导入数据命令-->
    <div id="dlg-buttonsImport">
        <a id="btnUpload" href="javascript:void(0)" class="easyui-linkbutton" >确定</a>
        <a id="btnQuit" href="javascript:void(0)" class="easyui-linkbutton" >取消</a>
    </div>

</asp:Content>
